﻿namespace ReactionGame
{
    internal class Program
    {
        /// <summary>
        /// ReactionGame
        /// </summary>
        /// <param name="args"></param>
        enum Direaction
        {
            Up,
            Down,
            Left,
            Right
        }
        const int countOfTest = 10;
        static void Main(string[] args)
        {
            int countOfError = 0;
            //随机数
            Random rnd = new Random();
            double reactionTime = 0;
            DateTime startTime = DateTime.Now;
            for (int i = 0; i < countOfTest; i++)
            {
                //依次开始测试
                Console.Clear();
                Console.WriteLine($"现在进行的是第{i + 1}次测试,总耗时{reactionTime}秒，共错{countOfError}次");
                Direaction direaction = (Direaction)rnd.Next(0,4);
                Console.WriteLine(direaction.ToString());
                bool flag = false;
                do
                {
                    //读入键盘指令
                    var key = Console.ReadKey();
                    switch (direaction)
                    {
                        case Direaction.Up:
                            if (key.Key == ConsoleKey.UpArrow) flag = true;
                            break;
                        case Direaction.Down:
                            if (key.Key == ConsoleKey.DownArrow) flag = true;
                            break;
                        case Direaction.Left:
                            if (key.Key == ConsoleKey.LeftArrow) flag = true;
                            break;
                        case Direaction.Right:
                            if (key.Key == ConsoleKey.RightArrow) flag = true;
                            break;
                        default:
                            break;
                    }
                    //输错后错误次数+1
                    if (flag == false) countOfError++;
                } while (flag == false);
                DateTime endTime = DateTime.Now;
                //计算总耗时
                reactionTime = (endTime - startTime).TotalSeconds;
            }
            Console.ReadKey();
        }
    }
}